unit flaboratoriocadastro;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  DBCtrls, StdCtrls, ExtCtrls, Buttons;

type

  { TFormLaboratorioCadastro }

  TFormLaboratorioCadastro = class(TForm)
    ButtonSair: TBitBtn;
    ButtonEditar: TBitBtn;
    ButtonSalvar: TBitBtn;
    ButtonCancelar: TBitBtn;
    ButtonBuscarMunicipio: TBitBtn;
    DBNomeLaboratorio: TDBEdit;
    DBNome_municipio: TDBEdit;
    DBUF: TDBEdit;
    DBCNPJ: TDBEdit;
    DBLogradouro: TDBEdit;
    DBBairro: TDBEdit;
    DBTelefone: TDBEdit;
    DBEmail: TDBEdit;
    DBCep: TDBEdit;
    DBPreco: TDBEdit;
    DBIdMunicipio: TDBEdit;
    DBComboTecnico: TDBLookupComboBox;
    GroupBox1: TPanel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Panel1: TPanel;
    procedure ButtonSairClick(Sender: TObject);
    procedure ButtonBuscarMunicipioClick(Sender: TObject);
    procedure ButtonCancelarClick(Sender: TObject);
    procedure ButtonEditarClick(Sender: TObject);
    procedure ButtonSalvarClick(Sender: TObject);
    procedure ControleBotaoes(Edicao: boolean);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormLaboratorioCadastro: TFormLaboratorioCadastro;

implementation

uses
  dmcadastro, dmlaboratorio;

{ TFormLaboratorioCadastro }

procedure TFormLaboratorioCadastro.ButtonBuscarMunicipioClick(Sender: TObject);
var
  municipio: TDadosMunicipio;
begin
  municipio := DataCadastro.MunicipioBusca();
  DBIdMunicipio.Text := IntToStr(municipio.id_municipio);
  DBNome_municipio.Text := municipio.nome_municipio;
  DBUF.Text := municipio.uf;
end;

procedure TFormLaboratorioCadastro.ButtonSairClick(Sender: TObject);
begin
  Close();
end;

procedure TFormLaboratorioCadastro.ButtonCancelarClick(Sender: TObject);
begin
  DataLaboratorio.LaboratorioCancelar();
  ControleBotaoes(False);
end;

procedure TFormLaboratorioCadastro.ButtonEditarClick(Sender: TObject);
begin
  DataLaboratorio.LaboratorioEditar();
  ControleBotaoes(True);
end;

procedure TFormLaboratorioCadastro.ButtonSalvarClick(Sender: TObject);
begin
  DataLaboratorio.LaboratorioSalvar();
  ControleBotaoes(False);
end;

procedure TFormLaboratorioCadastro.ControleBotaoes(Edicao: boolean);
begin
  if Edicao then
  begin
    ButtonEditar.Enabled := False;
    ButtonSair.Enabled := False;
    ButtonCancelar.Enabled := True;
    ButtonSalvar.Enabled := True;
  end
  else
  begin
    ButtonEditar.Enabled := True;
    ButtonSair.Enabled := True;
    ButtonCancelar.Enabled := False;
    ButtonSalvar.Enabled := False;
  end;
end;

initialization
  {$I flaboratoriocadastro.lrs}

end.
